﻿using System.Collections.Generic;
using System.Linq;
using System.Net;

namespace SimpleTFTP
{
    internal class Request
    {
        public OpCode OpCode { get; set; }

        public string FileName { get; set; }

        public List<byte> Data { get; set; }

        public byte[] LastBlockSent { get; set; }

        public short LastBlockNo { get; set; }

        public short LastBlockNoReceived { get; set; }

        public bool RequestComplete { get; set; }

        public EndPoint Client { get; set; }

        public byte[] GetNextDataBlock()
        {
            byte[] result = new byte[0];

            if (Data.Count >= 512)
            {
                result = Data.Take(512).ToArray();
                Data.RemoveRange(0, 512);
            }
            else
            {
                if (Data.Count != 0)
                {
                    result = Data.ToArray();
                    Data.Clear();
                }
            }

            return result;
        }
    }
}